package com.coder520.mamabike.user.entity;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 周国伟
 * @version 1.0
 * @describe 用于缓存user信息体
 * @date 2018/11/8 16:26
 */
@Data
public class UserElement {

    private long userId;

    private String mobile;

    private String token;

    private String platform;

    private String pushUserId;

    private String pushChannelId;

    /**
     * 转map
     *
     * @return map
     */
    public Map<String,String> toMap(){
        Map<String,String> map = new HashMap<>();
        map.put("userId",this.userId+"");
        map.put("mobile",this.mobile);
        map.put("token",this.token);
        map.put("platform",this.platform);
        if(pushUserId != null){
            map.put("pushUserId",this.pushUserId);
        }
        if(pushChannelId != null){
            map.put("pushChannelId",this.pushUserId);
        }
        return map;
    }
    /**
     * 转对象
     *
     * @param map
     * @return userElement
     */
    public static UserElement fromMap(Map<String,String> map){
        UserElement userElement = new UserElement();
        userElement.setUserId(Long.parseLong(map.get("userId")));
        userElement.setMobile(map.get("mobile"));
        userElement.setToken(map.get("token"));
        userElement.setPlatform(map.get("platform"));
        userElement.setPushUserId(map.get("pushUserId"));
        userElement.setPlatform(map.get("pushChannelId"));
        return userElement;
    }
}
